﻿import time

import requests
import json
import random
# cron:12 18 * * *
number = random.randint(10, 200)
print(f'随机延迟:{number}秒')

def generate_random_str(randomlength=16):
  """
  生成一个指定长度的随机字符串
  """
  random_str = ''
  base_str = 'abcdefghigklmnopqrstuvwxyz0123456789'
  length = len(base_str) - 1
  for i in range(randomlength):
    random_str += base_str[random.randint(0, length)]
  return random_str


cookie1 = 'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630898%2C%22studentname%22%3A%22%5Cu949f%5Cu96c5%5Cu83b9%22%2C%22parentname%22%3A%22%5Cu949f%5Cu706b%5Cu751f%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2219147067028%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3Anull%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%22%22%2C%22sh%22%3Anull%2C%22letter%22%3Anull%2C%22classname%22%3Anull%2C%22sq_sf%22%3A1%7D'
cookie2 = 'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630899%2C%22studentname%22%3A%22%5Cu949f%5Cu68a6%5Cu742a%22%2C%22parentname%22%3A%22%5Cu949f%5Cu6c34%5Cu5e73%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2213763907389%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3Anull%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%22%22%2C%22sh%22%3Anull%2C%22letter%22%3Anull%2C%22classname%22%3Anull%2C%22sq_sf%22%3A1%7D'
a = ''
phone = ['18162167526','15070715269','15779037819','18379716926','15089123560','18370843288','13173961577','18296707620','15270635509','15970814252','15270769650','13576666079','15297786376','15920814252','18166088655','18770744779','19970821886','18162167526','18770975725','15297786376','13479736928','17816208353','13576666079','17779738008','18162167526','18770744779','19970821886','18606967251','15179743788','18379716926','15170164920','17350331688','17370772126','18120687889','13237691602','18779782118','15270630289','17770786506','17779764066','14717571853','18162167526','13556330865','17770712692','13923977981','15079755706','15770762961','15779077556','18379716926','13237691602','18379709713']
def id2():
    headers = {
        #GET
    #http: // wpt.qmxyls.com / index / dyh_menu / news_day_ajax / id / 6 / page / 1
    #HTTP / 1.1
    'Host': 'wpt.qmxyls.com',
    'Connection': 'keep-alive',
    'Accept': '*/*',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6304051b)',
    'X-Requested-With': 'XMLHttpRequest',
    'Cookie':'',
    'Referer': 'http://wpt.qmxyls.com/index/dyh_menu/mschool.html',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',

    }

    url = f'http://wpt.qmxyls.com/index/dyh_menu/news_day_ajax/id/7'
    res = requests.get(url=url,headers=headers)
    a = json.loads(res.text)["data"][0]["id"]
    return a



def denglu():
    headers={
     #POSThttp: // wpt.qmxyls.com / index / login_dyh / index.html HTTP / 1.1
    'Host': 'wpt.qmxyls.com',
    'Connection': 'keep-alive',
    'Content-Length': '45',
    'Accept': '*/*',
    'Origin': 'http://wpt.qmxyls.com',
    'X-Requested-With': 'XMLHttpRequest',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6304051b)',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': f'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630899%2C%22studentname%22%3A%22%5Cu949f%5Cu68a6%5Cu742a%22%2C%22parentname%22%3A%22%5Cu949f%5Cu6c34%5Cu5e73%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2213763907389%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3Anull%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%22%22%2C%22sh%22%3Anull%2C%22letter%22%3Anull%2C%22classname%22%3Anull%2C%22sq_sf%22%3A1%7D',
    #'Cookie': generate_random_str(32),
    'Referer': 'http://wpt.qmxyls.com/index/login_dyh/index.html',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    }
    for i in phone:
        data = {'logintype': '1','password': '123456','phone': i}
        res = requests.post(url='http://wpt.qmxyls.com/index/login_dyh/index.html',data=data,headers=headers)
        res1 = requests.get(url='http://wpt.qmxyls.com/index/dyh_index.html',headers={'Host': 'wpt.qmxyls.com',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6304051b)',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Cookie': 'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630901%2C%22studentname%22%3A%22%5Cu949f%5Cu68a6%5Cu83e1%22%2C%22parentname%22%3A%22%5Cu949f%5Cu5f97%5Cu4e91%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2219179709316%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3A%22X20220104%22%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%2204%22%2C%22sh%22%3A2022%2C%22letter%22%3A%22X%22%2C%22classname%22%3A%2201%22%2C%22sq_sf%22%3A1%7D',
'Referer': 'http://wpt.qmxyls.com/index/login_dyh/index.html',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
})
        print(data)
        print(res.text)
        #print(res1.text)
        time.sleep(5)
        print(yuedu())
        #time.sleep(number)
        #res1 = requests.post(url='http://wpt.qmxyls.com/index/login_dyh/logout.html', headers=headers)

list = []

def yuedu():
    headers = {
        #POST    http: // wpt.qmxyls.com / index / dyh_menu / read_ajax.html    HTTP / 1.1
    'Host': 'wpt.qmxyls.com',
    'Connection': 'keep-alive',
    'Content-Length': '6',
    'Accept': '*/*',
    'Origin': 'http://wpt.qmxyls.com',
    'X-Requested-With': 'XMLHttpRequest',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6304051b)',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630899%2C%22studentname%22%3A%22%5Cu949f%5Cu68a6%5Cu742a%22%2C%22parentname%22%3A%22%5Cu949f%5Cu6c34%5Cu5e73%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2213763907389%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3Anull%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%22%22%2C%22sh%22%3Anull%2C%22letter%22%3Anull%2C%22classname%22%3Anull%2C%22sq_sf%22%3A1%7D',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',

    #id = 616
    }
    data = {'id':f'{random.choice(id1())}'}
    res = requests.post(url='http://wpt.qmxyls.com/index/dyh_menu/read_ajax.html',data=data,headers=headers)

    res1 = requests.get(url='http://wpt.qmxyls.com/index/dyh_menu/foster_ajax.html',headers={'Host': 'wpt.qmxyls.com',
'Connection': 'keep-alive',
'Accept': '*/*',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6304051b)',
'X-Requested-With': 'XMLHttpRequest',
'Cookie': 'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630898%2C%22studentname%22%3A%22%5Cu949f%5Cu96c5%5Cu83b9%22%2C%22parentname%22%3A%22%5Cu949f%5Cu706b%5Cu751f%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2219147067028%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3Anull%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%22%22%2C%22sh%22%3Anull%2C%22letter%22%3Anull%2C%22classname%22%3Anull%2C%22sq_sf%22%3A1%7D',
'Referer': 'http://wpt.qmxyls.com/index/dyh_menu/foster.html',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',})
    print(data)
    print(res.text)
    print(res1.text)

    print(data)
def id1():
    headers = {
        #GET
    #http: // wpt.qmxyls.com / index / dyh_menu / news_day_ajax / id / 6 / page / 1
    #HTTP / 1.1
    'Host': 'wpt.qmxyls.com',
    'Connection': 'keep-alive',
    'Accept': '*/*',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6304051b)',
    'X-Requested-With': 'XMLHttpRequest',
    'Cookie': 'PHPSESSID=6d849bf83b5139ca8b1a71176be0f08f; user_auth_d=%7B%22id%22%3A630898%2C%22studentname%22%3A%22%5Cu949f%5Cu96c5%5Cu83b9%22%2C%22parentname%22%3A%22%5Cu949f%5Cu706b%5Cu751f%22%2C%22city_id%22%3A17%2C%22area_id%22%3A235%2C%22street_id%22%3A1983%2C%22school_id%22%3A21967%2C%22classid%22%3A30247%2C%22tel%22%3A%2219147067028%22%2C%22email%22%3Anull%2C%22pwd%22%3A%2224026eee8538c996f677ee775d316013%22%2C%22pwd2%22%3A%22123456%22%2C%22reorder%22%3A0%2C%22status%22%3A1%2C%22jifen%22%3A0%2C%22dw_id%22%3A212%2C%22address%22%3Anull%2C%22pic%22%3A%22%5C%2Fstatic%5C%2Fimg%5C%2Ffile.png%22%2C%22ysdw_id%22%3A175%2C%22solar%22%3Anull%2C%22lunar%22%3Anull%2C%22enjoy%22%3A0%2C%22calendar_remark%22%3Anull%2C%22addtime%22%3A1642247604%2C%22student_number%22%3Anull%2C%22student_number_system%22%3Anull%2C%22header_img%22%3Anull%2C%22sex%22%3A0%2C%22update_time%22%3A0%2C%22xuhao%22%3A%22%22%2C%22sh%22%3Anull%2C%22letter%22%3Anull%2C%22classname%22%3Anull%2C%22sq_sf%22%3A1%7D',
    'Referer': 'http://wpt.qmxyls.com/index/dyh_menu/mschool.html',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',

    }
    for page in range(1,2):
        url = f'http://wpt.qmxyls.com/index/dyh_menu/news_day_ajax/id/7/page/{page}'
        res = requests.get(url=url,headers=headers)
        a = json.loads(res.text)
        for id2 in json.loads(res.text)["data"]:
            id3 = id2["id"]
            list.append(id3)
        #print(res.text)

    return list

denglu()
#print(id2())
#print(id1())
#id1()
#yuedu()